
//
//  WHMeTableViewHeaderCell.m
//  WHPersonalData
//
//  Created by mac on 2018/11/27.
//  Copyright © 2018年 mac. All rights reserved.
//

#import "WHMeTableViewHeaderCell.h"
#import "SDAutoLayout.h"
#import "WHMeModel.h"
#import "UIView+Rounded.h"

@interface WHMeTableViewHeaderCell ()
/**  头像   **/
//@property (nonatomic,weak)UIImageView * iconImageView;
@property (nonatomic,strong)UIButton * iconBtn;
/**  名字  **/
@property (nonatomic, strong)UILabel*nameLabel;
/**  微港号    **/
@property (nonatomic,strong)UILabel*qcodeLabel;
/**  二维码   **/
@property (nonatomic,strong)UIImageView *codeImageView;
/**  分割线    **/
@property (nonatomic,strong)UIView*separatorLine;

@end

@implementation WHMeTableViewHeaderCell

static NSString  *wHMeTableViewHeaderCellID = @"wHMeTableViewHeaderCellID";

+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    WHMeTableViewHeaderCell  * cell =[tableView dequeueReusableCellWithIdentifier:wHMeTableViewHeaderCellID];
    if (!cell) {
        cell = [[WHMeTableViewHeaderCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:wHMeTableViewHeaderCellID];
        cell.backgroundColor  = [UIColor clearColor];
    }
    return cell;
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        // init code here....
        [self setUpAllChilds];
    }
    return self;
}

-(void)setUpAllChilds
{
    /**   图片   **/
//    UIImageView*iconImageView =[[UIImageView alloc]init];
//    iconImageView.image = [UIImage imageNamed:@"人员1"];
//    [iconImageView setViewRoundedShadowWithRad:10 byRoundingCorners:UIRectCornerAllCorners];
//    [self.contentView  addSubview:iconImageView];
//    _iconImageView = iconImageView;
    
    [self.contentView  addSubview:self.iconBtn];
    
    /**   名字  **/
    UILabel*nameLabel = [[UILabel alloc]init];
    nameLabel.font = [UIFont systemFontOfSize:15*WidthScale>17?17:15*WidthScale];
    nameLabel.textColor =[UIColor blackColor];
    [self.contentView addSubview:nameLabel];
    nameLabel.text = @"蒋文创";
    _nameLabel = nameLabel;
    
    /**  微港号    **/
    UILabel*qcodeLabel = [[UILabel alloc]init];
    qcodeLabel.font = [UIFont systemFontOfSize:14*WidthScale>16?16:14*WidthScale];
    qcodeLabel.textColor =[UIColor blackColor];
    qcodeLabel.textAlignment = NSTextAlignmentLeft;
    [self.contentView addSubview:qcodeLabel];
    qcodeLabel.text = @"微港号:P0008";
    _qcodeLabel = qcodeLabel;
    
    /**   二维码   **/
    UIImageView*codeImageView =[[UIImageView alloc]init];
    [self.contentView  addSubview:codeImageView];
    codeImageView.image = [UIImage imageNamed:@"二维码"];
    _codeImageView = codeImageView;
    
    /**  分割线     **/
//    UIView*separatorLine =[[UIView alloc]init];
//    separatorLine.backgroundColor = [UIColor groupTableViewBackgroundColor];
//    [self.contentView addSubview:separatorLine];
//    _separatorLine = separatorLine;
    [self setUpChildLayout];
    
}

- (void)setUpChildLayout
{
    /**   图片   **/
    self.iconBtn.sd_layout
    .centerYEqualToView(self.contentView)
    .leftSpaceToView(self.contentView,27)
    .widthIs(60)
    .heightIs(60);
    self.iconBtn.layer.cornerRadius  = 30;
//    self.iconBtn.layer.masksToBounds = YES;
//    self.iconBtn.layer.borderWidth   = 0.5;
//    self.iconBtn.layer.borderColor   =RGBColor(14,152,224).CGColor;
    
    /**  名字  **/
    _nameLabel.sd_layout
        .topSpaceToView(self.iconBtn, -55)
    .leftSpaceToView(self.iconBtn ,kMarginH)
    .rightSpaceToView(self.contentView, kMarginH)
    .autoHeightRatio(0);
    
    /** 港号     **/
    _qcodeLabel.sd_layout
    .topSpaceToView(_nameLabel,kMarginH)
    .leftSpaceToView(self.iconBtn,kMarginH)
    .widthIs(kMarginH*11)
    .autoHeightRatio(0);
    
    /**   二维码   **/
    self.codeImageView.sd_layout
    .centerYEqualToView(self.contentView)
    .rightSpaceToView(self.contentView,kMarginH)
    .widthIs(2*kMarginH)
    .heightIs(2*kMarginH);
    self.codeImageView.layer.cornerRadius =5;

    /**  分割线     **/
//    self.separatorLine.sd_layout
//    .leftEqualToView(self.contentView)
//    .rightEqualToView(self.contentView)
//    .bottomEqualToView(self.contentView)
//    .heightIs(1);
    
    [self setupAutoHeightWithBottomViewsArray:@[self.iconBtn,self.qcodeLabel] bottomMargin:kMarginH];
}

-(void)setWHMeModel:(WHMeModel *)wHMeModel
{
    _wHMeModel = wHMeModel;
    
//    _iconImageView.image =[UIImage imageNamed:@"人员1"];
    if(wHMeModel.userName.length>1)
    {
        NSString *name = [wHMeModel.userName substringWithRange:NSMakeRange(wHMeModel.userName.length-2,2)];

        [self.iconBtn setTitle:name forState:UIControlStateNormal];
    }
    
    _nameLabel.text = _wHMeModel.userName;
    _qcodeLabel.text =[NSString stringWithFormat:@"微港号:%@",_wHMeModel.qcode];
}

-(UIButton *)iconBtn
{
    if (!_iconBtn)
    {
        _iconBtn = [[UIButton alloc] init];
        _iconBtn.titleLabel.font = [UIFont systemFontOfSize:20];
        _iconBtn.titleLabel.font = [UIFont boldSystemFontOfSize:20];
        _iconBtn.backgroundColor = RGBColor(54,141,246);
        [_iconBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [self.iconBtn setTitle:@"姓名" forState:UIControlStateNormal];
    }
    return _iconBtn;
}
@end

